
function basePath(){
    //获取当前网址，如： http://localhost:8080/ems/Pages/Basic/Person.jsp
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录，如： /ems/Pages/Basic/Person.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8080
    var localhostPath = curWwwPath.substring(0, pos);
    //获取带"/"的项目名，如：/ems
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    //获取项目的basePath   http://localhost:8080/ems/
    var basePath=localhostPath+projectName+"/";
    return basePath;
};

jQuery(document).ready(function() {
	initTable();

	//列表查询事件
	$('#search').click(function(){
		$('#repotTable').bootstrapTable(('refresh'));  // 很重要的一步，刷新url！
	});
	//详细页关闭
	$("#modalRepository").on("hidden.bs.modal", function() {
		$('#repotTable').bootstrapTable(('refresh')); 
	});
	
});	
//js函数
function initTable(){	
	
	$('#repotTable').bootstrapTable({
		method: 'post',
	    url: basePath() + 'repository/list.do',
	    pagination: true, //分页
	    dataType: "json",
        contentType: "application/json",
        pageList: [10, 20, 50, 100],  //可供选择的每页的行数（*）
        striped: true,      //是否显示行间隔色
        sidePagination: "server",
        ////查询参数,每次调用是会带上这个参数，可自定义                         
        queryParams:function(params) {
            return {
                	pageNum: params.offset / params.limit + 1,
                	pageSize: params.limit,
                	repositoryTitle: $('#repotTitle').val(),
                	keyWord: $('#repotKey').val(),
                	bigClass: $('#classBig').val(),
                	smallClass: $('#classSmall').val()
                };
        },
	    columns: [{  
            field : 'number',  
            title : '序号',  
            align : 'center',
            width : '80px',
            formatter : function(value, row, index) { 
// 		                return index + 1;  
                var page = $('#repotTable').bootstrapTable("getPage");  
                return page.pageSize * (page.pageNumber - 1) + index + 1;  
            }  
        }, {
	        field: 'repositoryCode',
	        title: '知识编号'
	    }, {
	        field: 'repositoryTitle',
	        title: '知识标题'
	    }, {
	        field: 'bigClass',
	        title: '大类'
	    }, {
	        field: 'smallClass',
	        title: '小类'
	    }, {
	        field: 'keyWord',
	        title: '关键字'
	    }, {
	        field: 'viewCount',
	        title: '浏览次数'
	    }, {
	        field: 'issuer',
	        title: '发布人'
	    }, {
	        field: 'releaseTime',
	        title: '发布时间'
	    }, {
	        field: 'status',
	        title: '状态',
	        formatter:function(value,row,index){
	        	var result = value;
	        	if(value == "1")
	        		result = "已审核";
	        	else 							
        			result = "未审核";
	        	return result;
	        }
	    }, {
	    	field: 'operate',
            title: '操作',
            align: 'center',
            width: '12%',
            events: operateEvents,
            formatter: operateFormatter
	    }]
	});
}
//详细按钮
function operateFormatter(value, row, index) {
    return [
        '<button type="button" class="detail btn btn-warning  btn-sm" style="margin-right:10px;"><span class="glyphicon glyphicon-list-alt"></span>详细</button>'
    ].join('');
}
window.operateEvents = {
	'click .detail': function (e, value, row, index) {
		var pk = row.repositoryPK;
		$("#modalRepository").modal('show');
		console.log(row);
		$("#code").html(row.repositoryCode);
		$("#tit").html(row.repositoryTitle);
		$("#big").html(row.bigClass);
		$("#small").html(row.smallClass);
		$("#keyword").html(row.keyWord);
		$("#state").html(row.status);
		$("#detail").html(row.detail);
	}
};


